﻿/* EllipseFitter_Qt.h
 * 
 * Copyright (C) 2020, 2021 Yuan LI
 * email:18069211@qq.com
 * https://blog.csdn.net/liyuanbhu
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or (at
 * your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#ifndef ELLIPSEFITTER_QT_H
#define ELLIPSEFITTER_QT_H

#include <QImage>

QPointF center(const QImage &image, int value);

class EllipseFitter_Qt
{
public:
    EllipseFitter_Qt();
    /**
     * @brief fit 将一片区域当作椭圆来估计五个几何参数
     * @param grayImage 传入的是一个灰度图像，其中值为 value 的区域是我们认为的物体所在区域
     * @param value 我们感兴趣的区域的值。通常这个值是 255
     * @return true 表示计算成功，结果存在 x_mean, y_mean, r1, r2, theta 这几个变量中。
     */
    bool fit(QImage grayImage, int value);

    /**
     * @brief center 计算一片区域的中心点（重心）
     * @param grayImage 传入的是一个灰度图像，其中值为 value 的区域是我们认为的物体所在区域
     * @param value 我们感兴趣的区域的值。通常这个值是 255
     * @return true 表示计算成功，结果存在 x_mean, y_mean
     */
    bool center(QImage grayImage, int value);

    double x_mean; //椭圆的中心坐标 x
    double y_mean; //椭圆的中心坐标 y
    double r1; //椭圆的长轴半径
    double r2; //椭圆的短轴半径
    double theta; //椭圆的长轴与 x 轴的夹角（逆时针）
};

#endif // ELLIPSEFITTER_QT_H
